package com.kedou.app;

import com.kedou.domain.User;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 资料修改 界面
 * 
 * @author zhouchao
 * 
 */
public class ModifyMyInformationActivity extends Activity implements
		OnClickListener {
	/**
	 * 中间 Title
	 */
	private TextView mTvTitle;
	/**
	 * 右侧 设置
	 */
	private ImageView mImgSetting;
	/**
	 * 头像 RelativeLayout
	 */
	private RelativeLayout mRlHead;
	/**
	 * 头像 右边的更多箭头
	 */
	private ImageView mImgHeadMore;
	/**
	 * 头像 图像
	 */
	private ImageView mImgHead;
	/**
	 * 昵称 RelativeLayout
	 */
	private RelativeLayout mRlNickname;
	/**
	 * 昵称 右边的更多箭头
	 */
	private ImageView mImgNicknameMore;
	/**
	 * 昵称 文本
	 */
	private TextView mTvNickname;
	/**
	 * 真实姓名 RelativeLayout
	 */
	private RelativeLayout mRlRealname;
	/**
	 * 真实姓名 右边的更多箭头
	 */
	private ImageView mImgRealnameMore;
	/**
	 * 真实姓名 文本
	 */
	private TextView mTvRealname;
	/**
	 * 身份证号码 RelativeLayout
	 */
	private RelativeLayout mRlIdNumber;
	/**
	 * 身份证号码 右边的更多箭头
	 */
	private ImageView mImgIdNumberMore;
	/**
	 * 身份证号码 文本
	 */
	private TextView mTvIdNumber;
	/**
	 * 身份认证 RelativeLayout
	 */
	private RelativeLayout mRlAuthentication;
	/**
	 * 身份认证 右边的更多箭头
	 */
	private ImageView mImgAuthenticationMore;
	/**
	 * 身份认证 是否认证 文本
	 */
	private TextView mTvCertification;
	/**
	 * 身份认证 图像
	 */
	private ImageView mImgCertification;
	/**
	 * 手机号码 RelativeLayout
	 */
	private RelativeLayout mRlPhoneNumber;
	/**
	 * 手机号码 右边的更多箭头
	 */
	private ImageView mImgPhoneNumberMore;
	/**
	 * 手机号码 文本
	 */
	private TextView mTvPhoneNumber;
	/**
	 * 邮箱 RelativeLayout
	 */
	private RelativeLayout mRlEmail;
	/**
	 * 邮箱 右边的更多箭头
	 */
	private ImageView mImgEmailMore;
	/**
	 * 邮箱 文本
	 */
	private TextView mTvEmail;
	/**
	 * 微信 RelativeLayout
	 */
	private RelativeLayout mRlWechat;
	/**
	 * 微信 右边的更多箭头
	 */
	private ImageView mImgWechat;
	/**
	 * 微信 文本
	 */
	private TextView mTvWechat;
	/**
	 * 用户相关
	 */
	private User user;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle bundle = getIntent().getBundleExtra("user");
		if (bundle != null) {
			user = bundle.getParcelable("user");
		}
		setContentView(R.layout.activity_modification);
		initView();
		setText();
		setListener();
	}

	/**
	 * 初始化View
	 */
	private void initView() {
		mTvTitle = (TextView) findViewById(R.id.title);
		mTvTitle.setText(R.string.title_modification);
		mImgSetting = (ImageView) findViewById(R.id.img_setting);
		mImgSetting.setVisibility(View.VISIBLE);
		mRlHead = (RelativeLayout) findViewById(R.id.rl_head);
		mImgHeadMore = (ImageView) findViewById(R.id.img_head_more);
		mImgHead = (ImageView) findViewById(R.id.img_head);
		mRlNickname = (RelativeLayout) findViewById(R.id.rl_nickname);
		mImgNicknameMore = (ImageView) findViewById(R.id.img_nickname_more);
		mTvNickname = (TextView) findViewById(R.id.tv_nickname);
		mRlRealname = (RelativeLayout) findViewById(R.id.rl_realname);
		mImgRealnameMore = (ImageView) findViewById(R.id.img_realname_more);
		mTvRealname = (TextView) findViewById(R.id.tv_realname);
		mRlIdNumber = (RelativeLayout) findViewById(R.id.rl_id_number);
		mImgIdNumberMore = (ImageView) findViewById(R.id.img_id_number_more);
		mTvIdNumber = (TextView) findViewById(R.id.tv_id_number);
		mRlAuthentication = (RelativeLayout) findViewById(R.id.rl_authentication);
		mImgAuthenticationMore = (ImageView) findViewById(R.id.img_authentication_more);
		mTvCertification = (TextView) findViewById(R.id.tv_whether_certification);
		mImgCertification = (ImageView) findViewById(R.id.img_whether_certification);
		mRlPhoneNumber = (RelativeLayout) findViewById(R.id.rl_phone_number);
		mImgPhoneNumberMore = (ImageView) findViewById(R.id.img_phone_number_more);
		mTvPhoneNumber = (TextView) findViewById(R.id.tv_phone_number);
		mRlEmail = (RelativeLayout) findViewById(R.id.rl_email);
		mImgEmailMore = (ImageView) findViewById(R.id.img_email_more);
		mTvEmail = (TextView) findViewById(R.id.tv_id_email);
		mRlWechat = (RelativeLayout) findViewById(R.id.rl_wechat);
		mImgWechat = (ImageView) findViewById(R.id.img_wechat_more);
		mTvWechat = (TextView) findViewById(R.id.tv_wechat);
	}

	/**
	 * 设置文本
	 */
	private void setText() {
		// TODO 头像
		mTvNickname.setText(user.getNickName());
		mTvRealname.setText(user.getRealName());
		mTvIdNumber.setText(user.getIDCard());
		initCertification(user.getCertStatus());
		mTvPhoneNumber.setText(user.getPhoneNum());
		mTvEmail.setText(user.getEmail());
		mTvWechat.setText(user.getWeChat());
	}

	/**
	 * 初始化认证状态
	 */
	protected void initCertification(int status) {
		switch (status) {
		// 已认证
		case 0:
			mTvCertification.setText(getResources().getString(
					R.string.has_certified));
			mImgCertification.setBackgroundResource(R.drawable.downlistretry);
			mRlRealname.setEnabled(false);
			mImgRealnameMore.setVisibility(View.INVISIBLE);
			mRlIdNumber.setEnabled(false);
			mImgIdNumberMore.setVisibility(View.INVISIBLE);
			mRlAuthentication.setEnabled(false);
			mImgAuthenticationMore.setVisibility(View.INVISIBLE);
			break;
		// 未认证
		case 1:
			mTvCertification.setText(getResources().getString(
					R.string.no_certified));
			mImgCertification.setBackgroundResource(R.drawable.no_cer);
			break;
		}
	}

	/**
	 * 设置监听器
	 */
	private void setListener() {
		mRlHead.setOnClickListener(this);
		mRlNickname.setOnClickListener(this);
		mRlRealname.setOnClickListener(this);
		mRlIdNumber.setOnClickListener(this);
		mRlAuthentication.setOnClickListener(this);
		mRlPhoneNumber.setOnClickListener(this);
		mRlEmail.setOnClickListener(this);
		mRlWechat.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.rl_head:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_nickname:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_realname:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_id_number:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_authentication:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_phone_number:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_email:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.rl_wechat:
			Toast.makeText(ModifyMyInformationActivity.this, "点击了",
					Toast.LENGTH_SHORT).show();
			break;
		}
	}
}
